'''
Created on 01/04/2009

@author: eh01
'''
import base64
import datetime
import httplib
import unittest


class Test(unittest.TestCase):


    def setUp(self):
        pass


    def tearDown(self):
        pass


    def testName(self):
        """ 
        Tests that Persistent (Keep-Alive) HTTP Connections are made
        Used Softpedia Tcp / IP Monitor To watch the TCP/IP connections made
        """
        # Sample code that keeps the tcp/ip connections alive
        username = '' # Put in username here
        password = '' # Put in password here
        base64string = base64.encodestring(
                '%s:%s' % (username, password))[:-1]
        auth_header =  "Basic %s" % base64string
        h = {
             'Authorization':auth_header
             }           
        conn = httplib.HTTPConnection("eplanning-vic-au.appspot.com")
        conn.set_debuglevel(9)
        samples = 1
        for i in range(samples):
            conn.request(method="GET", url="/node/1", headers=h)
            start = datetime.datetime.now()
            print 'Start Request: ' + str(start)           
            r1 = conn.getresponse()
            print r1.status, r1.reason
            print r1.read()
            end = datetime.datetime.now()
            print 'End Request: ' + str(end)
            print 'Time Taken: ' + str(end-start)
#            time.sleep(5)
        conn.close()

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()